package com.kabigon.tiny.config;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Jedis 连接池对象
 *
 * @author kabigon
 * @version 2022/9/25/00:42
 */
public class JedisConnectionFactory {

    private static final JedisPool jedisPool;

    static {
        // 配置连接池
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(8);
        poolConfig.setMaxIdle(8);
        poolConfig.setMinIdle(0);
        poolConfig.setMaxWaitMillis(1000);
        //常见连接池对象
        jedisPool = new JedisPool(poolConfig,
                "43.142.22.140", 6379, 1000, "whoami");
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }

}
